﻿using blackhouse.WebNemo.Business.Groups;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using blackhouse.WebNemo.Web;
using blackhouse.JavaScript.JQuery;

namespace blackhouse.StareKino.Web.HotelGallery {
    public partial class HotelGalleryModule : System.Web.UI.UserControl {

        protected void Page_Load(object sender, EventArgs e) {
            IGroup group = blackhouse.WebNemo.Business.Factory.Instance().GetGroup("ZDJECIA_APARTAMENTOW");
            GroupRecords records = new GroupRecords(group);
            GroupRecordQuery q = new GroupRecordQuery(group);
            q.SetProcedureName("bhp_GalleryGetAllPhotos");
            GroupRecord[] photoRecords = records.GetRecords(q);
            this.rptPhotos.DataSource = photoRecords;
            this.rptPhotos.DataBind();

            JQueryLibraries jql = new JQueryLibraries();
#if DEBUG
            jql.IncludeFileBasedOnJQuery("blackhouse.StareKino.Web.HotelGallery.hotel.gallery.js,blackhouse.StareKino.Web");
#else
            jql.IncludeFileBasedOnJQuery("blackhouse.StareKino.Web.HotelGallery.hotel.gallery.js,blackhouse.StareKino.Web");
#endif
        }

        protected void rptPhotos_ItemDataBound(object sender, RepeaterItemEventArgs e) {
            switch (e.Item.ItemType) {
                case ListItemType.Item:
                case ListItemType.AlternatingItem:
                    GroupRecord record = e.Item.DataItem as GroupRecord;
                    HyperLink lnkWithPhoto = e.Item.FindControl("lnkWithPhoto") as HyperLink;
                    if (record != null && lnkWithPhoto != null) {
                        lnkWithPhoto.ImageUrl = record.GetImageUrl("zdjecie", new System.Drawing.Size(150, 100));
                        lnkWithPhoto.NavigateUrl = record.GetImageUrl("zdjecie", new System.Drawing.Size(1800, 1600));
                        lnkWithPhoto.Attributes.Add("rel", "slimbox");
                    }
                    break;
            }
        }
    }
}